#define UNICODE 1

#include <stdio.h>
#include <windows.h>
#include <lm.h>
#include <lmdfs.h>

VOID usage(PWCHAR prog)
{
    fprintf( stderr, "usage: %S <DfsEntryPath> <ServerName> <SharePathName> [<on|off>]\n", prog );
}

int wmain(ULONG argc, PWCHAR *argv)
{
    DFS_INFO_101 DfsInfo101;
    ULONG Status;
    LPWSTR DfsEntryPath, ServerName = NULL, SharePathName = NULL;
    LPWSTR ResultString;

    if (argc != 5) {
        usage(argv[0]);
        return 1;
    }
    
    DfsEntryPath = argv[1];
    ServerName = argv[2];
    SharePathName = argv[3];

    if (!wcscmp( argv[4], L"on" )) {
        DfsInfo101.State = DFS_STORAGE_STATE_ONLINE;
        ResultString = L"enabled";
    } else if (!wcscmp( argv[4], L"off" )) {
        DfsInfo101.State = DFS_STORAGE_STATE_OFFLINE;
        ResultString = L"disabled";
    } else {
        usage(argv[0]);
        return 1;
    }

    //
    //  ... and modify it.
    //

    Status = NetDfsSetInfo( DfsEntryPath,
                            ServerName,
                            SharePathName,
                            101,
                            (LPBYTE) &DfsInfo101 );

    if (Status == NERR_Success) {
        printf( "\\\\%S\\%S -> %S\n", ServerName, SharePathName, ResultString );
    } else {
        fprintf( stderr, "error: %d\n", Status );
    }

    return 0;
}

